
package com.feib.soeasy.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.feib.soeasy.dao.FormatDefinitionDao;
import com.feib.soeasy.model.FormatDefinition;
import com.feib.soeasy.model.Group;
import com.feib.soeasy.model.LabelValue;
import com.feib.soeasy.pagination.PaginatedList;
import com.feib.soeasy.service.FormatDefinitionService;


/**
 * @title (#)FormatDefinitionServiceImpl.java<br>
 * @description <br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/11/20 create by Jimmy Liu<br>
 */
@Service("formatDefinitionService")
public class FormatDefinitionServiceImpl extends BaseServiceImpl implements FormatDefinitionService{


    @Resource(name="formatDefinitionDao")
    private FormatDefinitionDao formatDefinitionDao;
    
    public List<LabelValue> findLabelValueByFormatDefinition(FormatDefinition formatDefinition, boolean includeBatchUsed)
    {
        List<LabelValue> result = new ArrayList<LabelValue>();
        List<FormatDefinition> formatDefinitions = formatDefinitionDao.findByExample(formatDefinition);
        for(FormatDefinition d : formatDefinitions)
        {
            if (null != d.getBatchUsed() && d.getBatchUsed().booleanValue() && !includeBatchUsed)
            {
                continue;
            }
            LabelValue lv = new LabelValue();
            lv.setLabel(d.getFormatName());
            lv.setValue(d.getFormatDefinitionPk().toString());
            result.add(lv);
        }
        
        formatDefinitions.clear();
        formatDefinitions = null;
        
        return result;
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.FormatDefinitionService#queryByGroup(com.feib.soeasy.model.Group, com.feib.soeasy.pagination.PaginatedList)
     */
    @Override
    public PaginatedList<FormatDefinition> queryByGroup(Group group, PaginatedList<FormatDefinition> paginationConfig) {
        FormatDefinition formatDefinition = new FormatDefinition();
        formatDefinition.setGroup(group);
        return formatDefinitionDao.queryPaginationByFormatDefinition(formatDefinition, paginationConfig);
    }
    
    public FormatDefinition getFormatDefinitionByPk(Long formatDefinitionPk)
    {
        return this.formatDefinitionDao.findByPk(formatDefinitionPk);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.FormatDefinitionService#save(com.feib.soeasy.model.FormatDefinition)
     */
    @Override
    public FormatDefinition save(FormatDefinition formatDefinition) {
        return this.formatDefinitionDao.save(formatDefinition);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.FormatDefinitionService#delete(com.feib.soeasy.model.FormatDefinition)
     */
    @Override
    public void delete(FormatDefinition formatDefinition) {
        formatDefinitionDao.deleteById(formatDefinition.getFormatDefinitionPk());
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.FormatDefinitionService#queryByPk(java.lang.Long)
     */
    @Override
    public FormatDefinition queryByPk(Long formatDefinitionPk) {
        
        return this.formatDefinitionDao.findByPk(formatDefinitionPk);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.FormatDefinitionService#countFormatDefinitionByGroup(com.feib.soeasy.model.Group)
     */
    @Override
    public int countFormatDefinitionByGroup(Group group) {
        return this.formatDefinitionDao.countFormatDefinitionByGroup(group);
    }
}
